package com.ibeeking.found.msg.rest.controller.v1;


import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.found.msg.rest.service.IMpMiniprogramService;
import com.ibeeking.found.msg.service.common.param.MpMiniprogramParam;
import com.ibeeking.found.msg.service.common.query.MpMiniprogramPageQuery;
import com.ibeeking.found.msg.service.common.query.MpMiniprogramQuery;
import com.ibeeking.found.msg.service.common.vo.MpMiniprogramVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName MpMiniprogramController
 * @Description
 * @Author ibeeking
 * @Date 2021-02-02 20:18
 **/
@RestController
@RequestMapping("/b/wxMp/applet/v1")
public class MpMiniprogramController {

    @Resource
    private IMpMiniprogramService mpMiniprogramService;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "小程序列表")
    @PostMapping(value = "/list")
    public List<MpMiniprogramVO> list(@RequestBody MpMiniprogramQuery mpMiniprogramQuery) {
        return mpMiniprogramService.list(mpMiniprogramQuery);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "小程序分页查询")
    @PostMapping(value = "/pageList")
    public Page<MpMiniprogramVO> pageList(@RequestBody MpMiniprogramPageQuery mpMiniprogramPageQuery) {
        return mpMiniprogramService.pageList(mpMiniprogramPageQuery);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "添加小程序信息")
    @PostMapping(value = "/add")
    public Boolean add(@LoginUser CurrentUser currentUser, @RequestBody @Validated(BaseValidationGroup.Insert.class) MpMiniprogramParam mpMiniprogramParam) {
        mpMiniprogramParam.setCreateBy(currentUser.getId());
        mpMiniprogramParam.setModifyBy(currentUser.getId());
        return mpMiniprogramService.add(mpMiniprogramParam);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改小程序信息")
    @PostMapping(value = "/modify")
    public Boolean modify(@LoginUser CurrentUser currentUser,@RequestBody @Validated(BaseValidationGroup.Update.class) MpMiniprogramParam mpMiniprogramParam) {
        mpMiniprogramParam.setModifyBy(currentUser.getId());
        return mpMiniprogramService.modify(mpMiniprogramParam);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查看小程序信息详情")
    @GetMapping(value = "/view/{id}")
    public MpMiniprogramVO view(@PathVariable("id") Long id) {
        return mpMiniprogramService.view(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改小程序发布状态")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return mpMiniprogramService.changeStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除小程序")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return mpMiniprogramService.del(id);
    }
}
